#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "SafeMap.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    QRecursiveMutex s;
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{

    SafeMap<int, int> mapString2;
    mapString2.insert(10, 0);

    auto func = [](int& value)->int&
    {
        value += 1;
        return value;
    };

    QTime time;time.start();
    auto future1 = QtConcurrent::run([&]()
    {
        for (int i=0; i<10000 ; i++)
        {
            mapString2.modify(10, func);
        }

    });
    auto future2 = QtConcurrent::run([&]()
    {
        for (int i=0; i<10000 ; i++)
        {
            mapString2.modify(10, [](int& value)->int&
            {
                value += 1;
                return value;
            });
        }

    });


    future1.waitForFinished();
    future2.waitForFinished();

    qDebug()  << time.elapsed() << mapString2.getMap();
}
